package com.example.demo;


import org.apache.poi.xwpf.converter.pdf.PdfConverter;
import org.apache.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

public class DocToPdf4 {

    private static final String SUCCESS = "SUCCESS";
    private static final String ERROR ="ERROR";
    public static void main(String[] args) {
        try {

            //读取word文档
            XWPFDocument document = null;
            try (InputStream in = Files.newInputStream(Paths.get("C:\\tempFiles\\第一课：zookeeper 特性与节点说明.docx"))) {
                document = new XWPFDocument(in);
            } catch (IOException e) {
                e.printStackTrace();
            }

            //将word转成pdf
            PdfOptions options = PdfOptions.create();
            try (OutputStream outPDF = Files.newOutputStream(Paths.get("C:\\tempFiles\\test2007.pdf"))) {
                PdfConverter.getInstance().convert(document, outPDF, options);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
